package com.self.war.presenter;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.myself.entities.Post;
import com.myself.repositories.PostRepository;
import com.self.war.view.UserView;
/**
 * 
 * User view presenter
 * @see com.self.war.presenter.Presenter
 * @author kamel.mahdi
 *
 */
@SuppressWarnings("serial")
@Component
public class UserPresenter implements Presenter<UserView> {
	UserView userView;

	@Autowired
	PostRepository postRepository;

	public UserView getUserView() {
		return userView;
	}

	public void setUserView(UserView userView) {
		this.userView = userView;
	}

	/**
	 * return the list of post
	 * 
	 * @return
	 */
	public List<Post> getPosts() {
		return postRepository.findAll();
	}

	@Override
	public UserView getView() {
		return userView;
	}

	@Override
	public void setView(UserView view) {
		this.userView = view;
	}

	public PostRepository getPostRepository() {
		return postRepository;
	}

	public void setPostRepository(PostRepository postRepository) {
		this.postRepository = postRepository;
	}

	public void initData() {
		List<Post> posts = new ArrayList<Post>();
		for (int i = 0; i < 1000; i++) {
			Post post = new Post();
			post.setPostDate(new Date());
			post.setTitle("title" + i);
			posts.add(post);
		}
		postRepository.save(posts);
	}
}
